//
//  ZYCCourseSelectCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/23.
//

#import "ZYCCourseSelectCell.h"
//#import "ZWPaddingLabel.h"
#import "ZYCCourseRegistrationModel.h"
#import <UIImageView+WebCache.h>
#import "UIImage+imgaeWithColor.h"

@interface ZYCCourseSelectCell ()

@property (nonatomic, strong) UIImageView *courseIconView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *courseStatusLabel;
// 课程类型
@property (nonatomic, strong) UILabel *genreLabel;
// 所属课程
@property (nonatomic, strong) UILabel *sortLabel;
// 授课老师
@property (nonatomic, strong) UILabel *teacherLabel;
// 报名人数
@property (nonatomic, strong) UILabel *numLabel;
@end
@implementation ZYCCourseSelectCell


- (void)setModel:(ZYCCourseRegistrationModel *)model{
    _model = model;
    NSURL *url  = [NSURL URLWithString:[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.courseImg]];
    [_courseIconView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder_image_icon"]];
    _titleLabel.text = model.className;
    //报名状态（1-未开始，2-进行中，3-已结束）
    NSInteger enrollStatus = [model.enrollStatus integerValue];
    if (enrollStatus == 1) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#EB9F28");
    }else if (enrollStatus == 2) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#39A85B");
    }else if (enrollStatus == 3) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#B9B9B9");
    }
    _courseStatusLabel.text = model.enrollStatusStr;
    _genreLabel.text = [NSString stringWithFormat:@"课程类型: %@",model.courseTypeName];
    _sortLabel.text = [NSString stringWithFormat:@"所属课程: %@",model.courseName];
    _teacherLabel.text = [NSString stringWithFormat:@"授课老师: %@",model.teacherName];
    _numLabel.text = model.enrollRate;
}

//- (void)setDict:(NSDictionary *)dict{
//    _dict = dict;
//    _courseIconView.image = [UIImage imageNamed:@""];
//    _titleLabel.text = dict[@"title"];
//    _courseStatusLabel.text = dict[@"status"];
//    if ([dict[@"statusNum"] isEqualToString:@"1"]) {
//        _courseStatusLabel.backgroundColor = HEX_RGB(@"#EB9F28");
//    }else if ([dict[@"statusNum"] isEqualToString:@"2"]) {
//        _courseStatusLabel.backgroundColor = HEX_RGB(@"#39A85B");
//    }else {
//        _courseStatusLabel.backgroundColor = HEX_RGB(@"#B9B9B9");
//    }
//    _genreLabel.text = [NSString stringWithFormat:@"课程类型: %@",dict[@"gen"]];
//    _sortLabel.text = [NSString stringWithFormat:@"所属课程: %@",dict[@"sort"]];
//    _teacherLabel.text = [NSString stringWithFormat:@"所属课程: %@",dict[@"teacher"]];
//    _numLabel.text = dict[@"num"];
//
//}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.courseIconView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.courseStatusLabel];
        [self.contentView addSubview:self.courseIconView];
        [self.contentView addSubview:self.genreLabel];
        [self.contentView addSubview:self.sortLabel];
        [self.contentView addSubview:self.teacherLabel];
        [self.contentView addSubview:self.numLabel];
        
        [self.courseIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(274/2, 189/2));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.courseIconView.mas_right).offset(10.0f);
            make.right.equalTo(self.courseStatusLabel.mas_left).offset(-5.0f);
            make.top.equalTo(self.courseIconView);
        }];
        
        [self.courseStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-25.0f);
            make.centerY.equalTo(self.titleLabel);
            make.size.mas_equalTo(CGSizeMake(56.0f, 23.0f));
        }];
        [self.genreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15.0f);
            make.left.equalTo(self.titleLabel);
        }];
        [self.sortLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.genreLabel.mas_bottom).offset(9.0f);
            make.left.equalTo(self.titleLabel);
        }];
        [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.sortLabel.mas_bottom).offset(9.0f);
            make.left.equalTo(self.titleLabel);
        }];
        [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-25.0f);
            make.centerY.equalTo(self.teacherLabel);
        }];
    }
    return self;
}

- (UIImageView *)courseIconView {
    if (!_courseIconView) {
        _courseIconView = [[UIImageView alloc] init];
        _courseIconView.layer.cornerRadius = 5.0f;
        _courseIconView.layer.masksToBounds = YES;
        _courseIconView.backgroundColor = [UIColor grayColor];
    }
    return _courseIconView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(15.0f) titleColor:HEX_RGB(@"#000000") textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 1;
    }
    return _titleLabel;
}

- (UILabel *)courseStatusLabel {
    if (!_courseStatusLabel) {
        _courseStatusLabel = [[UILabel alloc] init];
        _courseStatusLabel.textColor = HEX_RGB(kTitleWhiteColor);
        _courseStatusLabel.font = kCustomFont(@"PingFangSC-Light", 12.0f);
        _courseStatusLabel.layer.cornerRadius = 11.5;
        _courseStatusLabel.layer.masksToBounds = YES;
        _courseStatusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _courseStatusLabel;
}

- (UILabel *)genreLabel {
    if (!_genreLabel) {
        _genreLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _genreLabel;
}

- (UILabel *)sortLabel {
    if (!_sortLabel) {
        _sortLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _sortLabel;
}

- (UILabel *)teacherLabel {
    if (!_teacherLabel) {
        _teacherLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _teacherLabel;
}

- (UILabel *)numLabel {
    if (!_numLabel) {
        _numLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _numLabel;
}
@end
